function changeFormat(num){
	var num
	num = num.toString().replace(/\$|\,|\./g,''); 
	if(isNaN(num)) 
		num = "0"; 
	sign = (num == (num = Math.abs(num))); 
	num = Math.floor(num*100+0.50000000001); 
	num = Math.floor(num/100).toString(); 

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) 
	num = num.substring(0,num.length-(4*i+3))+'.'+ num.substring(num.length-(4*i+3)); 
	var akhirDP = ((sign)?'':'-') + num;
	return akhirDP;
}// JavaScript Document

function hitungBensinPerKM(f){
	f.perKM.value=changeFormat(f.perKM.value);	
	hitungaall(f);
}

function hitungBensinKMawal(f){
	f.KMawal.value=changeFormat(f.KMawal.value);
	hitungaall(f);
}
function hitungBensinKMakhir(f){
	f.KMakhir.value=changeFormat(f.KMakhir.value);
	hitungaall(f);
}
function hitungBensinHarga(f){
	f.hargaBensin.value=changeFormat(f.hargaBensin.value);
	hitungaall(f);
}
function hitungBensinDipakai(f){
	f.bensinPakai.value=changeFormat(f.bensinPakai.value);
	hitungaall(f);
}

function hitungaall(f){
	perKM = Number(f.perKM.value.replace(/[^0-9]+/g,""));
	KMawal = Number(f.KMawal.value.replace(/[^0-9]+/g,""));
	KMakhir = Number(f.KMakhir.value.replace(/[^0-9]+/g,""));
	hargaBensin = Number(f.hargaBensin.value.replace(/[^0-9]+/g,""));
	bensinPakai = Number(f.bensinPakai.value.replace(/[^0-9]+/g,""));
	
	KMtot = KMakhir-KMawal;
	literTotal = KMtot * perKM;
	hargaTot = literTotal * hargaBensin
	untung = hargaTot - bensinPakai;
	if (untung < 0) {
     	status = "Rugi" ;
	}else if(untung == 0)
	{
		status = "Netral"	
	}else
	{
		status = "Untung"
	}
	f.statman.value = status;

	untung = changeFormat(untung);
	f.hasil.value = untung;
}

